import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class TestServer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("admin123");
        factory.setVirtualHost("/admin");
        Connection connection = factory.newConnection();
        String queueName = "testservice";
        final Channel channel = connection.createChannel();
        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("=======test======="+new String(body));
                AMQP.BasicProperties replyProps = new AMQP.BasicProperties.Builder()
//                        .correlationId(properties.getCorrelationId())
                        .correlationId("hehe====")
                        .build();
                String response = "hai I'm server";
                channel.basicPublish("",properties.getReplyTo(),replyProps,response.getBytes());
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        };
        channel.basicConsume(queueName,false,consumer);
    }
}
